package jjn.carl.hashtable;

/**
 * @author Jjn
 * @since 2023/7/3 14:18
 */
public class LeetCode242 {
    public boolean isAnagram(String s, String t) {
        if (s == null && t == null) {
            return true;
        }
        if (s == null || t == null) {
            return true;
        }
        if (s.length() != t.length()) {
            return false;
        }
        char[] firstIndex = new char[26];
        for (char c : s.toCharArray()) {
            firstIndex[c - 'a']++;
        }
        char[] secondIndex = new char[26];
        for (char c : t.toCharArray()) {
            secondIndex[c - 'a']++;
        }
        for (int i = 0; i < firstIndex.length; i++) {
            if (firstIndex[i] != secondIndex[i]) {
                return false;
            }
        }
        return true;
    }
    
    public static void main(String[] args) {
        System.out.println("new LeetCode242().isAnagram(\"rat\", \"tar\") = " + new LeetCode242().isAnagram("rat", "tar"));
    }
}
